/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : camTrigger.cpp
  * Description        : 
  ******************************************************************************
  * Function           :
  *
  ******************************************************************************
  * Author             : Zhiping Fu
  * Creation Date      : Oct 23, 2020
  ******************************************************************************
  */
/* USER CODE END Header */

#include "camTrigger.hpp"
#include "string.h"



void CAMTRIGGER::camTrigger_Init(void)
{
	Sta = STA_INI;
	Err = ERR_NONE;
	UnLock = false;
	executionTime_us = 0;
	cycleTime_us = 0;
	linux_init_success = false;
	linux.linux_init_success = false;
	xQueueOverwrite(queueLinux,&linux);
	LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_9);
	LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_8);
}

void CAMTRIGGER::camTrigger_Run(){


	LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_8);
	osDelay(1);
	LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_8);

	getTimer_us(&startTimer);
	camTrigger.pic_index++;
	camTrigger.pic_timestamp = startTimer;
	xQueueOverwrite(queueCamTrigger,&camTrigger);
}


CAMTRIGGER camTrigger;
extern "C" void camTrigger_main(void *argument)
{
	static u32 cnt = 0;
	camTrigger.camTrigger_Init();

	for(;;)
	{
		osSemaphoreAcquire(semCamTrigger,0xffffffff);
		cnt++;

		xQueuePeek(queueLinux, &camTrigger.linux, 0);
		camTrigger.linux_init_success = camTrigger.linux.linux_init_success;

		if(cnt%200==0&&camTrigger.linux_init_success==true){
			camTrigger.camTrigger_Run();
			led1_Tog;
			led2_Tog;
		}
	}
}


/************************ (C) COPYRIGHT Longmen Drone Team *****END OF FILE****/
